package br.com.news.database.services;

import java.util.List;

import javax.inject.Inject;
import javax.inject.Named;

import br.com.news.database.daos.interfaces.ICategoriaDao;
import br.com.news.database.entities.CategoriaEntity;
import br.com.news.database.exception.DataBaseException;
import br.com.news.database.utils.GenericService;
import br.com.news.database.utils.interfaces.IGenericDao;
import br.com.news.utils.database.beans.CategoriaBean;
import br.com.news.utils.database.exception.DataBaseServiceException;
import br.com.news.utils.database.interfaces.ICategoriaServiceDb;

@Named

public class CategoriaServiceDb extends GenericService<CategoriaBean, CategoriaEntity, Long> implements ICategoriaServiceDb{
	@Inject
	private ICategoriaDao catedoriaDao;

	@Override
	protected IGenericDao<CategoriaEntity, Long> getConcreteDao() {
		return this.catedoriaDao;
	}

	@Override
	public List<CategoriaBean> findCategoriaByUsuarioName(String login) throws DataBaseServiceException {
		try {
			return parserEntity(this.catedoriaDao.findCategoriaByUsuarioName(login));
		} catch (DataBaseException e) {
			throw new DataBaseServiceException(e);
		}
	}

	@Override
	public List<CategoriaBean> findCategoriaByStatus(boolean status)
			throws DataBaseServiceException {
		try {
			return parserEntity(this.catedoriaDao.findCategoriaByStatus(status));
		} catch (DataBaseException e) {
			throw new DataBaseServiceException(e);
		}
	}
	
	@Override
	public List<CategoriaBean> categoriasMaisAcessadas() throws DataBaseServiceException {
		try {
			return parserEntity(catedoriaDao.categoriasMaisAcessadas());
		} catch (DataBaseException e) {
			throw new DataBaseServiceException(e);
		}
	}
	
	@Override
	public Long quantidadeCarregadas(Long idCategoria) {
		return catedoriaDao.quantidadeCarregadas(idCategoria);
	}
	
	@Override
	public List<CategoriaBean> findByExample(CategoriaBean categoria) {
		return parserEntity(catedoriaDao.findByExample(parserBean(categoria)));
	}

}
